// pages/apps/parking/parking-detail.ts
Page({
  /**
   * 页面的初始数据
   */
  data: {
    latitude: 26.3553348789,
    longitude: 106.4254533487898,
    markers: [] as any[],
    customCalloutMarkerIds: [],
    num: 1,
    item: null,
    parkingBean: {
      id: '',
      name: '',
      locLat: 26.3553348789,
      locLng: 106.4254533487898
    }
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad() {
    var that = this
    const eventChannel = this.getOpenerEventChannel()
    eventChannel.on('beanData', function (param) {
      console.error("param参数：" + JSON.stringify(param.bean))
      that.setData({ parkingBean: param.bean })

      var allMarkers = [] as any[];
      const marker = {
        id: that.data.parkingBean.id,
        latitude: that.data.parkingBean.locLat,
        longitude: that.data.parkingBean.locLng,
        callout: {
          // 点击marker展示title
          content: param.bean.name
        }
      }
      allMarkers.push(marker)

      that.setData({
        latitude: allMarkers[0].latitude,
        longitude: allMarkers[0].longitude,
        markers: allMarkers
      })

      // 设置标题
      wx.setNavigationBarTitle({
        title: that.data.parkingBean.name
      })
    })
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady() {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow() {
  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide() {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload() {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh() {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom() {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage() {

  },
  /**
   * 打开导航
   */
  toParkingNavi(param: any) {
    const item = param.currentTarget.dataset.bean
    console.error("toParkingNavi:" + JSON.stringify(item))
    wx.openLocation({
      latitude: item.locLat, // 纬度，范围为-90~90，负数表示南纬
      longitude: item.locLng, // 经度，范围为-180~180，负数表示西经
      scale: 13, // 缩放比例
      name: item.name,
      address: item.address,
      success: function (r) {
        console.log(r)
      }
    })
  },
  doCall(param: any) {
    const item = param.currentTarget.dataset.bean
    console.error("toParkingNavi:" + JSON.stringify(item))
    var phone = item.loaderPhone
    wx.makePhoneCall({
      phoneNumber: phone,
      success: function (res) {
        console.log('拨打电话成功！');
      },
      fail: function (res) {
        console.log('拨打电话失败！');
      }
    })
  },
})